package com.suxin.test;

import com.suxin.domain.Goods;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @author Tang
 * @classname GoodsMapper
 * @description [  ]
 * @date 2021/3/9 9:37
 */
public interface GoodsMapper {

    @Select("select  * from goods where goods_id between #{param1} and #{param2}")
    List<Goods> findAllByGoodsIdBetween(Long goodsId1, Long goodsId2);

    @Select(value = {
            "<script>",
            "select * from goods where goods_id in ",
            "<foreach collection = 'goodsIds' open='(' separator=',' close=')' >",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    List<Goods> findAllByGoodsIdIn(List<Long> goodsIds);

    @Insert("insert into goods (goods_id,goods_name,goods_type,create_time) value ( #{goodsId},#{goodsName} ,#{goodsType},now() )")
    int insert(Goods goods);

    @ResultMap(value = {"Goods"})
    @Select("select  * from goods where goods_id = #{param1} limit 1")
    Goods findAllById(int goodsIds);

    @Results(id = "Goods",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(id = true,column = "goods_type",property = "goodsType"),
            @Result(id = true,column = "goods_name",property = "goodsName"),
            @Result(id = true,column = "goods_id",property = "goodsId"),
            @Result(id = true,column = "create_time",property = "createTime")
    })
    @Select("select  * from goods where create_time >= #{createTime} and create_time <= #{endTime} ")
    List<Goods> findAllByCreateTime(@Param("createTime") Date createTime,@Param("endTime") Date endTime);

}
